
var shareInfo = {
    _linkUrl        : 'http://scale.yoparent.cn/scale-pos-psy/app/index.html',
    _imgUrl         : 'http://static.xingfuchuangke.cn/common/yoparent_share_logo.png', //分享图片地址
    _descTitle      : '儿童心智成长评估',                             	//分享标题
    _descContent    : '本鉴定以剑桥大学儿童心智成长十大维度为核心，鉴定儿童心智成长指数，帮助家长更加了解孩子的各项优势。',     //分享语
}

function getQueryString(name){
      var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if(r!=null)return  unescape(r[2]); return null;
  }

var getWXInfo = function(){
	$.ajax({
      	url: HTTPRouter.getWXInfoUrl,
      	type: 'GET',
      	data:{
      		url:encodeURI(window.location.href),
      	},
      	dataType: 'json',
      	error: function (e) {
        	console.log("请求异常！");
      	},
      	success: function (paperDate) {
	        paperDate  = JSON.parse(paperDate);

          // 修改了token的机制
          var tokenParam = getQueryString("token");
          var _token = tokenParam? tokenParam: paperDate.token;

	        AppStorage.setValueInSession("token", _token);
	        initWXConfig(paperDate);
      	}
    });

}();

function initWXConfig(date){
    wx.config({
      debug: false,
      appId: date.singatureParm.appId,
      timestamp: date.singatureParm.timestamp,
      nonceStr: date.singatureParm.nonceStr,
      signature: date.singatureParm.signature,
      startTime: date.startTime,
      jsApiList: [
        'onMenuShareTimeline',
        'onMenuShareAppMessage'
      ]
    });
   wxReady();
}

function wxReady(){
    wx.ready(function () {
	  	wx.onMenuShareTimeline({
		    title: shareInfo._descTitle,
		    link: shareInfo._linkUrl,
		    imgUrl: shareInfo._imgUrl,
		    success: function () {},
		    cancel: function () {},
		    fail:function (res) {
		      // alert("分享失败：" +JSON.stringify(res));
		    }
	  	});
		wx.onMenuShareAppMessage({
		    title: shareInfo._descTitle,
		    desc: shareInfo._descContent,
		    link: shareInfo._linkUrl,
		    imgUrl: shareInfo._imgUrl,
		    type: 'link',
			dataUrl: '',
			success: function () {},
			cancel: function () {},
			fail:function (res) {
			  // alert("分享失败：" +JSON.stringify(res));
			}
		});
    });
}
